package com.trinity.campus.controller;

import com.trinity.campus.domain.CampusSchoolOrg;
import com.trinity.campus.service.ICampusSchoolOrgService;
import com.trinity.common.annotation.Log;
import com.trinity.common.core.controller.BaseController;
import com.trinity.common.core.domain.AjaxResult;
import com.trinity.common.core.page.TableDataInfo;
import com.trinity.common.enums.BusinessType;
import com.trinity.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学校组织机构Controller
 *
 * @author dsp
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/campus/org")
public class CampusSchoolOrgController extends BaseController {
    @Resource
    private ICampusSchoolOrgService campusSchoolOrgService;

    /**
     * 查询某个节点
     */
    @PreAuthorize("@ss.hasPermi('campus:org:list')")
    @GetMapping("/option")
    public AjaxResult option(CampusSchoolOrg campusSchoolOrg) {
        return success(campusSchoolOrgService.schoolOrgOption(campusSchoolOrg));
    }

    /**
     * 查询学校组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('campus:org:list')")
    @GetMapping("/page")
    public TableDataInfo page(CampusSchoolOrg campusSchoolOrg) {
        startPage();
        List<CampusSchoolOrg> list = campusSchoolOrgService.selectCampusSchoolOrgList(campusSchoolOrg);
        return getDataTable(list);
    }

    /**
     * 查询学校组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('campus:org:list')")
    @GetMapping("/list")
    public AjaxResult list(CampusSchoolOrg campusSchoolOrg) {
        List<CampusSchoolOrg> list = campusSchoolOrgService.selectCampusSchoolOrgList(campusSchoolOrg);
        return success(list);
    }

    /**
     * 导出学校组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('campus:org:export')")
    @Log(title = "学校组织机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampusSchoolOrg campusSchoolOrg) {
        List<CampusSchoolOrg> list = campusSchoolOrgService.selectCampusSchoolOrgList(campusSchoolOrg);
        ExcelUtil<CampusSchoolOrg> util = new ExcelUtil<>(CampusSchoolOrg.class);
        util.exportExcel(response, list, "学校组织机构数据");
    }

    /**
     * 获取学校组织机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:org:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(campusSchoolOrgService.selectCampusSchoolOrgById(id));
    }

    /**
     * 新增学校组织机构
     */
    @PreAuthorize("@ss.hasPermi('campus:org:add')")
    @Log(title = "学校组织机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampusSchoolOrg campusSchoolOrg) {
        return toAjax(campusSchoolOrgService.insertCampusSchoolOrg(campusSchoolOrg));
    }

    /**
     * 修改学校组织机构
     */
    @PreAuthorize("@ss.hasPermi('campus:org:edit')")
    @Log(title = "学校组织机构", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CampusSchoolOrg campusSchoolOrg) {
        return toAjax(campusSchoolOrgService.updateCampusSchoolOrg(campusSchoolOrg));
    }

    /**
     * 删除学校组织机构
     */
    @PreAuthorize("@ss.hasPermi('campus:org:remove')")
    @Log(title = "学校组织机构", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}/delete")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(campusSchoolOrgService.deleteCampusSchoolOrgByIds(ids));
    }
}
